<template>
  <yt-page title="隐患清单" scroll>
    <yt-card btn="查看更多详情" v-for="(item, index) in items" :key="index" @btn-click="goDetailPage(item)">
      <yt-cell border="none" label="检查时间" :value="item.check_time"></yt-cell>
      <yt-cell border="none" label="检查人" :value="item.check_person"></yt-cell>
      <yt-cell border="none" label="层级" :value="getListLevelVal(item.list_level)"></yt-cell>
      <yt-cell border="none" label="隐患级别" :value="LEVEL[item.Hidden_danger_level].D_text"></yt-cell>
      <yt-cell border="none" label="隐患状态" :value="STATE[item.state]"></yt-cell>
      <yt-cell border="none" label="隐患内容" :value="item.text"></yt-cell>
    </yt-card>
  </yt-page>
</template>

<script>
import { commonApi } from '@/common/api/commonApi.js'

const LEVEL = [
  {
    D_text: '一般隐患',
    D_code: '1'
  },
  {
    D_text: '重大隐患',
    D_code: '2'
  }
]
const STATE = {
  1: '未整改',
  3: '已整改'
}

export default {
  data() {
    return {
      LEVEL,
      STATE,
      listLevelDic: [],
      rightData: [
        {
          font: 'yt-icon yt-icon-search',
          click: () => {
            this.searchBox = !this.searchBox
          }
        }
      ],
      active: [],
      items: [],
      des: '从事机械生产'
    }
  },
  activated() {
    if (this.$router.$isBack) return
    this.items = []
    this.refresh()
  },
  methods: {
    async refresh() {
      let param = Object.assign(
        { equalTo: this.$route.query },
        { include: ['enterprise_name'] }
      )
      let items = await this.$Loading(
        commonApi.search('Hidden_Trouble_Investigation', param)
      )
      this.listLevelDic = await commonApi.dictionary('hierarchy')
      this.items = items
    },
    goDetailPage(item) {
      this.$router.$push({ name: '隐患详情', params: item })
    },
    getListLevelVal(listLevel) {
      if (!this.listLevelDic.length) return
      let item = this.listLevelDic.filter(item => {
        return item.D_code === listLevel
      })
      return item[0].D_text
    }
  }
}
</script>

<style lang="stylus" scoped>
>>> .flex
  display flex
  justify-content space-between
  padding 10px
  border-bottom 0.5px solid #f5f5f5

>>> .yt-cell-label
  padding 0
</style>
